package albino.dao;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import albino.domain.Group;
import albino.domain.User;

@Repository
public class UserDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	public User getByUsername(String username) {
		
		return (User)sessionFactory.getCurrentSession().
				createCriteria(User.class)
				.add(Restrictions.eq("username",username))
				.uniqueResult();
	}

	public void installUser(User user) {
		sessionFactory.getCurrentSession().save(user);
	}
	
	public void installGroup(Group group) {
		sessionFactory.getCurrentSession().save(group);
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
}
